<?php
namespace app;

use think\facade\View;
use app\BaseController;
use app\admin\model\User;

/**
 * 控制器基础类
 */
class FrameBaseController extends BaseController 
{

    public function __construct() {
        include_once dirname(__FILE__) . "/define.php";
        $this->initialize();
    }

    // 初始化
    protected function initialize() {
        $this->checkInstall();
    }

    protected function checkInstall() {
        $lock_file = public_path() . 'ncore' . DIRECTORY_SEPARATOR . 'install.lock';
        if (file_exists($lock_file)) {
            return TRUE;
        }
        header("Location:/install.php/");
        exit;
    }

    public function jump404() {
        //只有在app_debug=False时才会正常显示404页面，否则会有相应的错误警告提示
        abort(404, '页面异常');
    }

    public function frameTpl($title = null, $list = null) {
        $result = get_curr_user();
        View::assign([
            'uid'      => $result['id'],
            'username' => $result['username'],
            'password' => $result['password'],
            'status'   => $result['status'],
            'title'    => $title,
        ]);
        if (null != $list) {
            View::assign('list', $list);
        }
        return View::fetch('public/head') . View::fetch() . View::fetch('public/foot');
    }

    /**
     * 未登录
     */
    public function isNotLogin($title = '', $text = '') {
        $result = get_curr_user();
        View::assign([
            'uid'      => $result['id'],
            'username' => $result['username'],
            'password' => $result['password'],
            'status'   => $result['status'],
            'title'    => $title,
            'text'     => $text,
        ]);
        return View::fetch('public/head') . View::fetch('public/isnotlogin') . View::fetch('public/foot');
    }

    //空方法
    public function _empty() {
        return $this->jump404();
    }

}
